<template>
  <div v-enter-helper="getList" class="app-container">
    <el-card class="box-card">
      <div slot="header" class="clearfix">

        <el-row>
          <el-form
            ref="dataList2"
            :inline="true"
            :model="listQuery"
            class="demo-form-inline"
          >
            <el-form-item label="">
              <el-input
                v-model.number="listQuery.user_code"
                clearable
                placeholder="用户编号"
                type="text"
              ></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="handleRemoveBlock(listQuery.user_code)">解除</el-button>
            </el-form-item>
          </el-form>
        </el-row>
      </div>
      <div class="item">
        <el-table
          ref="dataList"
          v-loading="listLoading"
          :data="tableList"
          :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
          border
          row-key="id"
          style="width:100%;margin-bottom: 20px;"
        >
          <el-table-column label="用户ID" prop="user_id"></el-table-column>
          <el-table-column label="用户编号" prop="user_code"></el-table-column>
          <el-table-column label="用户昵称" prop="nickname"></el-table-column>
          <el-table-column label="违规时间" prop="block_time"></el-table-column>
          <!-- <el-table-column prop="remark" label="账号状态">
              <template slot-scope="scope">

              </template>
          </el-table-column> -->
          <el-table-column label="操作" width="250px">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="handleRemoveBlock(scope.row.user_code)"
              >解除私聊限制
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页 -->
        <!-- <cus-pagination
          :total="total"
          :page.sync="listQuery.page"
          :limit.sync="listQuery.perPage"
          @pagination="getList"
        /> -->
      </div>
    </el-card>

  </div>
</template>

<script>
import { listData, removeBlock } from '@/api/member/privateChatViolationList'

export default {
  name: 'privateChatViolationList',
  data() {
    return {
      confirmBtn: false,
      listLoading: false,
      tableList: [],
      total: 10,
      listQuery: {
        page: 1,
        perPage: 10,
        user_code: undefined
      }
    }
  },
  async created() {
    await this.getList()
  },
  methods: {
    async getList() {
      const res = await listData(this.listQuery)
      this.tableList = res.data
      // this.total = res.data.meta.total;
      this.confirmBtn = false
    },
    handleRemoveBlock(user_code) {
      this.$confirm('是否解除私聊限制?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.removeBlockFun({
          user_code: user_code
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消操作'
        })
      })
    },
    removeBlockFun(data) {
      removeBlock(data).then(res => {
        if (res.code === 200) {
          this.$message({
            type: 'success',
            message: '操作成功'
          })
          this.getList()
        }
      })
    }
  }
}
</script>

<style scoped>
[v-cloak] {
  display: none;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both;
}

.box-card {
  width: 100%;
}

</style>
